import { ElMessage } from 'element-plus'

export const copyText = (text) => {
  if (!text) return false

  const textArea = document.createElement('textarea')
  textArea.value = text
  document.body.appendChild(textArea)
  textArea.select()

  try {
    document.execCommand('copy')
    ElMessage.success('已复制到剪贴板')
    document.body.removeChild(textArea)
    return true
  } catch (err) {
    ElMessage.error('复制失败')
    document.body.removeChild(textArea)
    return false
  }
} 